﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class KhachHang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["AdminName"] != null)
            {
                DisplayList();
            }
            else
                Response.Redirect("Default.aspx");
        }
    }
    protected void DisplayList()
    {
        string sql = "select * from customers";
        DataTable dt = DataBase.GetDataTable(sql);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string sql = "delete from customers where CustomerID='" + GridView1.Rows[e.RowIndex].Cells[1].Text + "'";
        try
        {
            DataBase.ExecuteNonQuery(sql);
            DisplayList();
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        this.DisplayList();
    }
}
